#include "DeviceManager.h"

ReturnStatus DeviceManager::addDevice(int deviceType,const string& deviceStatus){

    if(Database.connect()==ReturnStatus::SUCCESS){
        
        string query = "INSERT INTO devices (device_type, status,last_modified) VALUES ('"+to_string(static_cast<int>(deviceType))+"', '"+deviceStatus+"','"+GET_CURRENT_TIME()+"')";
        if(Database.executeQuery(query)==ReturnStatus::SUCCESS){
            cout<<DEVICEADDSUCCESS<<endl;
            return SUCCESS;
        }
    }
    cout<<DEVICEADDFAILURE<<endl;
    return FAILURE;
}

ReturnStatus DeviceManager::deleteDevice(int deviceId){
    if(Database.connect()==ReturnStatus::SUCCESS){
        
        string query = "DELETE FROM devices WHERE id = "+to_string(deviceId);
        if(Database.executeQuery(query)==ReturnStatus::SUCCESS){
            cout<<DEVICEDELETESUCCESS<<endl;
            return SUCCESS;
        }
    }
    cout<<DEVICEDELETEFAILURE<<endl;
    return FAILURE;
}

vector<Device> DeviceManager::getDevice(int userId,Role role){
    vector<Device> results;
    if(Database.connect()==ReturnStatus::SUCCESS){
        if(role==ROLEADMIN){
            string query = "SELECT * FROM devices";
            vector<string> results = Database.fetchResults(query,TABLEDEVICE);
           
            
        }else{
            string query = "SELECT * FROM devices WHERE user_id = "+to_string(userId);
            vector<string> results = Database.fetchResults(query,TABLEDEVICE);
        }
       // string query = "SELECT * FROM devices WHERE user = '"+username+"' AND password = '"+password+"'";
        //vector<string> results = Database.fetchResults(query,TABLEUSER);
    }
    return results;
}